/**
 * @file 03-type-aliases.ts
 * 
 * 1.3.3 使用类型别名简化类型声明
 */

import { RangeValidationBase } from "./01-union-type"
export type StringOrNumber = string | number;

export class UnionRangeValidationWithTypeAlias extends RangeValidationBase {
    IsInRange(value: StringOrNumber): boolean {
        if (typeof value === "number") {
            return this.RangeCheck(value);
        }
        return this.RangeCheck(this.GetNumber(value));
    }
}

if (new UnionRangeValidationWithTypeAlias(10, 20).IsInRange("10")) {
    console.log(`This value is in range`);
}
if (new UnionRangeValidationWithTypeAlias(10, 20).IsInRange(9)) {
    console.log(`This value is in range`);
}
if (new UnionRangeValidationWithTypeAlias(10, 20).IsInRange(15)) {
    console.log(`This value is in range`);
}
if (new UnionRangeValidationWithTypeAlias(10, 20).IsInRange("20")) {
    console.log(`This value is in range`);
}
if (new UnionRangeValidationWithTypeAlias(10, 20).IsInRange(21)) {
    console.log(`This value is in range`);
}